package com.xp.interview.controller;

import com.xp.interview.model.NoteModel;
import com.xp.interview.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by xp on 15/10/15.
 */
@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;

    @RequestMapping(value = "/search",method = RequestMethod.GET)
    @ResponseBody
    public List<NoteModel> queryNote(@RequestParam(value = "key",required = true) String key,
                            Model model) {
        List<NoteModel> notes = searchService.queryNote(key);
        model.addAttribute("notes",notes);
        return notes;
//        return "index";
    }
}
